package com.cxb;

import java.util.Locale;

import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.provider.Settings;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.TextView;

import com.cxb.utils.CommonUtils;
import com.cxb.utils.Constants;
import com.cxb.utils.Debug;
import com.cxb.utils.SharedPreferencesUtils;

public class SetupWizardActivity1 extends BaseActivity {
	private View btnQuickSet;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		// this.getWindow().addFlags(
		// WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

		setLanguage(Locale.CHINA);// 设置默认语言为中文

		setContentView(R.layout.activity_setupwizard);
		/** 改为永不关屏 **/
		Settings.System.putInt(getApplicationContext().getContentResolver(),
				Settings.System.SCREEN_OFF_TIMEOUT,
				Constants.Setting.SCREEN_TIMEOUT_DELAY_FOREVER);
		init();
	}

	private void setLanguage(Locale locale) {
		try {
			Class<?> activityManagerNative = Class
					.forName("android.app.ActivityManagerNative");
			Object am = activityManagerNative.getMethod("getDefault").invoke(
					activityManagerNative);
			Object config = am.getClass().getMethod("getConfiguration")
					.invoke(am);

			config.getClass().getDeclaredField("locale").set(config, locale);
			config.getClass().getDeclaredField("userSetLocale")
					.setBoolean(config, true);
			am.getClass().getMethod("updateConfiguration", Configuration.class)
					.invoke(am, config);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	private void init() {
		btnQuickSet = findViewById(R.id.bt_quicksetup);

		btnQuickSet.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				// Intent i = new Intent();
				// i.setClass(SetupWizardActivity1.this,
				// SetupWizardActivity2.class);
				// startActivity(i);
				// finish();

				new SharedPreferencesUtils(SetupWizardActivity1.this)
						.setIsSetupWizard(true);
				Intent i = new Intent();
				i.setClass(SetupWizardActivity1.this, MainActivity.class);
				startActivity(i);
				finish();
			}
		});

	}

	int count = 0;

	public boolean onTouchEvent(android.view.MotionEvent event) {

		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			if (event.getX() < 70 && event.getY() >= 250) {
				count++;
			} else {
				count = 0;
			}
			Debug.printf("test", "count=" + count);
			if (count >= 6) {
				Intent intent = new Intent();
				intent.setClassName("com.zzx.factorytest",
						"com.zzx.factorytest.MainActivity");
				intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				startActivity(intent);
			}
		}
		return false;

	};
}
